<% include header.ejs %>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">代理/用户管理</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <div class="row">
        <table id="userUnreviewTable" class="table dataTable datatable_ table-striped table-bordered table-condensed">
            <thead>
            <th>id</th>
            <th>代理名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>照片</th>
            <th>地址</th>
            <th>优惠次数</th>
            <th>申请时间</th>
            <th>邀请码</th>
            <th>操作</th>
            <!--<th>描述</th>-->
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->
<div class="modal fade" id="userUnreviewDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <!--modal-lg-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">信息详情</h4>
            </div>
            <div class="modal-body" style="min-height:350px">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="confirmUpdateUser(this)">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<% include footer.ejs %>
<script type="text/javascript">
    $(function(){
        findAllApply()
    })
    function findAllApply() {
        var url = "examine/findAllApply";
        $.ajax({
            url: url,
            method: 'post',
            success: function (res) {
//                alert(res.msg)
                console.log(res)
                userUnreviewTable(res)
                $('.examine').children('b').text(res.length)
            },
            error: function () {

            }

        })
    }
    function userUnreviewTable(data){
        $('#userUnreviewTable').DataTable({
            destroy: true,
            "bAutoWidth": false,
            responsive: true,
            data: data,
            "aoColumnDefs": [
                { "bSortable": false, "aTargets": [ 4,5,8,9] },
                {
                    "render": function(data, type, row) {
                        return (new Date(parseInt(data))).toLocaleString();
                    },
                    "targets": 7
                },
                {
                    "render": function(data, type, row) {
                        var html = "<img src='"+data+"' />"
                        return html;
                    },
                    "targets": 4
                },
                {
                    "render": function(data, type, row) {
                        var html;
                        html = "<button data-id="+data.id+" class='btn btn-sm btn-primary' onclick='passApply(this)'>通过</button>"+
                            "<button data-id="+data.id+" class='btn btn-sm btn-danger' onclick='rejectApply(this)" +
                            "'>不通过</button>"
                        return html
                    },
                    "targets": 9
                },
            ],
            columns: [
                {
                    data: 'id'
                },{
                    data: 'name'
                },{
                    data: 'sex'
                },{
                    data: 'age'
                },{
                    data: 'icon'
                },{
                    data: 'address'
                },{
                    data: 'discount'
                },{
                    data: 'creationTime',
                },
                {
                    data: 'inviCode',
                },
                {
                    data: null
                },
            ],
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            },
            "fnCreatedRow": function (nRow, aData, iDataIndex) {
//                console.log(nRow)
            },
            "fnRowCallback": function (nRow, aaData, iDisplayIndex, iDisplayIndexFull) {
            }
        })
    }
    function rejectApply(btn){
        var id = $(btn).attr("data-id")
        $.ajax({
            url: "examine/rejectApply",
            method: 'post',
            data:{
                id:id
            },
            success: function (res) {
//                alert(res.msg)
                console.log(res)
                findAllApply()
            },
            error: function () {

            }

        })
    }
    function passApply(btn){
        var id = $(btn).attr("data-id")
        $.ajax({
            url: "examine/passApply",
            method: 'post',
            data:{
                id:id
            },
            success: function (res) {
//                alert(res.msg)
                console.log(res)
                findAllApply()
            },
            error: function () {

            }

        })
    }
</script>
</html>